/* eslint-disable camelcase */
const eventClass = require('./eventClass');
const os = require('./os');

const path_ = eval('require')('path');
const child_process = eval('require')('child_process');

class commandClass extends eventClass {
    constructor() {
        super('dirClass');
        this.os = (new os()).type;
    }

    copyDir(cb, { target, source }) {
        let err = null;
        try {
            target = path_.resolve(target);
            source = path_.resolve(source);
            if (this.os === 'win') {
                child_process.exec(`cmd /c xcopy /Y /E /I "${source}" "${target}"`);
            } else {
                child_process.spawnSync('cp', ['-r', source, target]);
            }
        } catch (e) {
            err = e;
        } finally {
            this.returnMethod(cb, { err });
        }
    }
}

module.exports = commandClass;
